package com.up.vms.domain.vm.repository;

import com.up.vms.domain.vm.entity.ShortVideo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;

public interface ShortVideoRepository extends JpaRepository<ShortVideo, Long>, JpaSpecificationExecutor<ShortVideo> {
    Page<ShortVideo> findAllByStatus(Integer code, Pageable pageable);
    Page<ShortVideo> findAllByStatusLessThan(Integer code, Pageable pageable);

    Optional<ShortVideo> findByShortIdAndCreatorAndStatusLessThan(Long shortId, String creator, Integer status);


    @Modifying
    @Query(value = "update T_VMS_Short_Video v set v.play_times = v.play_times + 1 where v.short_id = ?1", nativeQuery = true)
    void updatePlayTimes(Long id);
}
